package com.chy.blog_server.modular.web.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.chy.blog_server.core.util.PageAndParamUtil;
import com.chy.blog_server.modular.web.entity.BoImgLog;
import com.chy.blog_server.modular.web.service.IBoImgLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 描述：文章内容图片上传记录表 controller
 * 作者：chenhuiyan
 * 时间：2020/03/01 22:07
 */
@Controller
@RequestMapping(value = "/web/boImgLog")
public class BoImgLogController {

    /**
     * 前缀
     */
    private static String PREFIX = "web/boImgLog/";

    @Autowired
    private IBoImgLogService boImgLogService;

    /**
     * 内容图片列表首页
     * @return
     */
    @RequestMapping(value = "/boContentImg")
    public String boContentImg(){
        return PREFIX + "boImgLog_content";
    }

    /**
     * 查询内容图片列表
     * @return
     */
    @RequestMapping(value = "/boContentImgList")
    @ResponseBody
    public Map<String, Object> boContentImgList(){
        Map<String, Object> res = new HashMap<>();
        try{
            Map<String, Object> params = PageAndParamUtil.getParams();
            params.put("tableName", "bo_content"); //内容表名
            List<Map<String, Object>> list = boImgLogService.list(params); //获取数据列表
            Integer count = boImgLogService.getCount(params); //获取总数
            res.put("code", 0);
            res.put("msg", "获取数据成功");
            res.put("count", count);
            res.put("data", list);
        }catch (Exception e){
            e.printStackTrace();
            res.put("code", 500);
            res.put("msg", "获取数据失败");
        }
        return res;
    }

    /**
     * 文章图片列表首页
     * @return
     */
    @RequestMapping(value = "/boArticleImg")
    public String boArticleImg(){
        return PREFIX + "boImgLog_article";
    }

    /**
     * 查询文章图片列表
     * @return
     */
    @RequestMapping(value = "/boArticleImgList")
    @ResponseBody
    public Map<String, Object> boArticleImgList(){
        Map<String, Object> res = new HashMap<>();
        try{
            Map<String, Object> params = PageAndParamUtil.getParams();
            params.put("tableName", "bo_article"); //文章表名
            List<Map<String, Object>> list = boImgLogService.list(params); //获取数据列表
            Integer count = boImgLogService.getBaseMapper().selectCount(new QueryWrapper<BoImgLog>().eq("table_name", "bo_article")); //获取总数
            res.put("code", 0);
            res.put("msg", "获取数据成功");
            res.put("count", count);
            res.put("data", list);
        }catch (Exception e){
            e.printStackTrace();
            res.put("code", 500);
            res.put("msg", "获取数据失败");
        }
        return res;
    }

    /**
     * 个人日记图片列表首页
     * @return
     */
    @RequestMapping(value = "/boPersonalDiaryImg")
    public String boPersonalDiaryImg(){
        return PREFIX + "boImgLog_personalDiary";
    }

    /**
     * 查询个人日记图片列表
     * @return
     */
    @RequestMapping(value = "/boPersonalDiaryImgList")
    @ResponseBody
    public Map<String, Object> boPersonalDiaryImgList(){
        Map<String, Object> res = new HashMap<>();
        try{
            Map<String, Object> params = PageAndParamUtil.getParams();
            params.put("tableName", "bo_personal_diary"); //个人日记表名
            List<Map<String, Object>> list = boImgLogService.list(params); //获取数据列表
            Integer count = boImgLogService.getBaseMapper().selectCount(new QueryWrapper<BoImgLog>().eq("table_name", "bo_personal_diary")); //获取总数
            res.put("code", 0);
            res.put("msg", "获取数据成功");
            res.put("count", count);
            res.put("data", list);
        }catch (Exception e){
            e.printStackTrace();
            res.put("code", 500);
            res.put("msg", "获取数据失败");
        }
        return res;
    }

}
